<?php

namespace App\Datas;

abstract class ClickHouse {

    private $client = null;

    public function getClient() {
        if (!empty($this->client)) {
            return $this->client;
        }

        $config = [
            "host" => env("CH_HOST"),
            "port" => env("CH_PORT"),
            "username" => env("CH_USER"),
            "password" => env("CH_PWD")
        ];
        try {
            $this->client = new \ClickHouseDB\Client($config);
            $this->client->database(env("CH_DATABASE"));
            $this->client->setTimeout(env("CH_TIMEOUT",10));
        } catch (\Exception $e) {
            var_dump($e->getMessage());
        }
        return $this->client;
    }
}